
$(function() {
	initData();
	initButton();
    
});


/**
 * 初始化数据
 */
function initData(){
	queryLinkMan();//初始化查询列表
}

/**
 * 初始化按钮
 */
function initButton(){
	
	$(".press_btn1").click(function() {
		queryLinkMan();
	});
	$(".press_btn2").click(function() {
		deleteman();
	});
	$('.addbtn').click(function(){
        layer.config({
            extend:['skin/layer_iframe.css'],
            skin:'layer-ext-skin-layer_iframe.css'
        });
        layer.open({
            type:2,
            title:'添加联系人',
            area:['600px','400px'],

            content:basePath+'/radar/config/initaddlinkman.do',
            maxmin: true,
            shadeClose: true

        });
    });
}

/**查询联系人
 * @returns
 */
function queryLinkMan(){
	var linkGroup= [ {code : 'thirdPartyLinkmansId',name : 'checkBox',width : 10},
	                {code : 'linkmanName',name : '姓名'}, 
	                {code : 'mobilePhone',name : '电话'}, 
	                {code : 'email',name : '邮件'}, 
	                {code : 'department',name : '所属部门'}, 
	                {code : 'pany',name : '所属公司'},
	                {code : 'E_D_R',name : '操作'}, ];
	var parm = {
		url : basePath + '/radar/config/getlinkman.do',
		divID : 'linkman'
	};
	// 常规参数
	var data = {
		'linkmanName' : $("#linkmanName").val(),
		'mobilePhone': $("#mobilePhone").val(),
		'email': $("#email").val(),
		'pany': $("#pany").val(),
		'department': $("#department").val(),
	}; // 赛选

	easyQuery(linkGroup, parm, data);
}

function deleteman(){
	var id = '';
	$("input[type='checkbox'][nodeId][ divID='linkman']:checked").each(function() {
		id = id + $(this).attr("nodeId") + ",";
	});
	if (id == '') {
		layer.msg('请选择要删除的选项', {
			icon : 1
		});
		return;
	}
	id = id.substring(0, id.length - 1);
	delLinkman(id);
}


function edit_linkman(thisObj){
	var $td = $(thisObj).parents('tr').children('td');
	var linkmanName = $td.eq(1).text();
	var mobilePhone = $td.eq(2).text();
	var email = $td.eq(3).text();
	var department = $td.eq(4).text();
	var pany = $td.eq(5).text();
	var linkmanid = $(thisObj).parents('tr').attr('nodeId');
	layer.config({
        extend:['skin/layer_iframe.css'],
        skin:'layer-ext-skin-layer_iframe.css'
    });
    layer.open({
        type:2,
        title:'添加第三方联系人',
        area:['600px','400px'],
        content:basePath+'/radar/config/initaddlinkman.do?linkmanName='+linkmanName+'&mobilePhone='+mobilePhone+'&email='+email+'&department='+department+'&pany='+pany+'&editflag='+1+'&linkmanid='+linkmanid,
        maxmin: true,
        shadeClose: true

    });
}

/**操纵按钮 删除
 * @param f
 */
function del_linkman(f) {
	var id=$(f).parent().parent().attr("nodeId");
	delLinkman(id );	
}

/**操纵操作
 * @param f
 */
function delLinkman(id ){
	var index = layer.confirm("确认删除？", {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		$.ajax({
			url : basePath+"/radar/config/dellinkman.do",
			type : "POST",
			dataType:"json",
			data : {
				"id":id
			},
			success:function(data){
				if(data.errorMessage == ""){
					layer.msg('删除成功！', {icon : 1});
					reQuery('linkman');
				}
			}
		});

});
}
/**关联按钮  关联联系人组
 * @param f
 */
function rela_linkman(f){
	var linkmanId=$(f).parent().parent().attr("nodeId");
    layer.config({
        extend:['skin/layer_iframe.css'],
        skin:'layer-ext-skin-layer_iframe.css'
    });
    layer.open({
        type:2,
        title:'关联联系人',
        area:['800px','400px'],

        content:basePath+'/radar/config/linkGroup.do?linkmanId='+linkmanId,
        maxmin: true,
        shadeClose: true
    });
}
